<?php
include_once($_SERVER['DOCUMENT_ROOT'] . '/mba/models/DonVi.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/mba/controls/CapNhatDonViController.php');
?>

<script type="text/javascript">
// funtion lay gia tri tu radio button "chon"
    function getValue(id) {
        document.capnhatdonvi.txtmadv.value = document.getElementById("madv" + id).innerHTML;
        document.capnhatdonvi.txttendv.value = document.getElementById("tendv" + id).innerHTML;
        document.capnhatdonvi.txtdiachidv.value = document.getElementById("diachidv" + id).innerHTML;
        document.capnhatdonvi.txtlienhedv.value = document.getElementById("lienhedv" + id).innerHTML;
        document.capnhatdonvi.txttentk.value = document.getElementById("tentk" + id).innerHTML;
        document.capnhatdonvi.txtmatkhau.value = document.getElementById("matkhau" + id).innerHTML;
        document.capnhatdonvi.txtquyen.value = document.getElementById("quyen" + id).innerHTML;
        // chuyen mau cac textfield tendv,diachidv,lienhedv thanh mau trang', va cho phep sua doi thong tin
        document.capnhatdonvi.txtmadv.readOnly = true;
        document.capnhatdonvi.txtmadv.style.backgroundColor = '#cccccc';
        document.capnhatdonvi.txttendv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtdiachidv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtlienhedv.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txttentk.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.txtmatkhau.style.backgroundColor = '#FFFFFF';
        document.capnhatdonvi.btnsuadv.disabled = false;
        document.capnhatdonvi.btnxoadv.disabled = false;
        document.capnhatdonvi.txttendv.readOnly = false;
        document.capnhatdonvi.txtdiachidv.readOnly = false;
        document.capnhatdonvi.txtlienhedv.readOnly = false;
        document.capnhatdonvi.txttentk.readOnly = false;
        document.capnhatdonvi.txtmatkhau.readOnly = false;
        document.capnhatdonvi.txtquyen.disabled = false;
    }
// fuction hien bang xac nhan truoc khi xoa don vi
    function confirmDelete() {
        if (confirm("Bạn có chắc muốn xóa đơn vị này không?")) {
            return true;
        }
        return false;
    }
</script>
<html>
    <head>
        <meta charset=utf-8 />
        <title>Cập nhật đơn vị</title>
        <style type="text/css">
        </style>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <!--<link href="../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
        <script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>-->
    </head>

    <body>
        <div class="bodyStyle">
            <p></p>
            <form name="capnhatdonvi" method="post" action="">
                <!-- bang hien thi -->  
                <table align="center" class="font" width="900px" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align=center class="TableHeader"  height="20" >Cập nhật đơn vị </td>
                    </tr>
                    <tr bgcolor="#dae9f3">
                        <td class="border_1" colspan="3" valign="top"><table width="793" border="0" align="center" >
                                <tr>
                                    <td width="132" >Mã đơn vị :</td>
                                    <td width="257" align="left" ><input name="txtmadv" type="text" id="txtmadv" style="background-color:#CCCCCC" size="10" maxlength="100" readonly ><br>
                                  </td>
                                    <td width="123" align="left" style="font-size: 12;">&nbsp;</td>
                                    <td width="263" align="left" style="font-size: 12;">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td>Tên đơn vị : </td>
                                    <td><input name="txttendv" type="text" id="txttendv"  style="background-color:#CCCCCC" size="40" maxlength="100" readonly ><br>

                                    </td>
                                    <td align="left" >Địa chỉ đơn vị : </td>
                                    <td align="left"><input name="txtdiachidv" type="text" id="txtdiachidv"  style="background-color:#CCCCCC" size="40" maxlength="100" readonly /></td>
                                </tr>        

                                <tr>
                                    <td>Tên tài khoản : </td>
                                    <td><input name="txttentk" type="text" id="txttentk" style="background-color:#CCCCCC" size="40" maxlength="100" readonly >          <br></td>
                                    <td align="left" >Mật khẩu : </td>
                                    <td align="left" ><input name="txtmatkhau" type="text" id="txtmatkhau" style="background-color:#CCCCCC" size="40" maxlength="100" readonly ></td>
                                </tr>
                                <tr>


                                    <td><span >Thông tin liên hệ : </span></td>
                                    <td><span >
                                            <input name="txtlienhedv" type="text" id="txtlienhedv" style="background-color:#CCCCCC" size="40" maxlength="100" readonly >
                                        </span><br></td>
                                    <td align="left" >Quyền : </td>
                                    <td align="left" ><select name="txtquyen" id="txtquyen" disabled>
                                            <option value="0" selected></option>
                                            <option value="1">Phòng KH-KT (1)</option>
                                            <option value="2">Đơn vị thành viên (2)</option>
                                            <option value="3">Đơn vị nhập số liệu (3)</option>
                                        </select></td>

                                </tr>
                                <tr>
                                    <td colspan="4" class="btn" id="btn" >
                                        <input type="submit" name="btnthemdv" id="btnthemdv" value="Thêm đơn vị">
                                        <input type="submit" name="btnsuadv" id="btnsuadv" value="Sửa đơn vị" disabled="true">
                                        <input type="submit" name="btnxoadv" id="btnxoadv" value="Xóa đơn vị"  disabled="true" onClick="confirmDelete()">
                                    </td>
                                </tr>
                            </table></td>
                    </tr>
                </table>
                </br>

                <!-- lay du lieu tu bang don vi va hien thi -->
                <?php
                $donvi = new DonVi();
                $result = $donvi->dsDonVi();
                echo "<table align='center' width='900px' border='0' cellspacing='0' cellpadding='0' ";
                echo "<tr>";
                echo "<td align='center' class='TableHeader'> Danh sách đơn vị</td>";
                echo "</tr>";
                echo "<tr >";
                echo "<td colspan='3' valign='top'><table width='900' border='0' cellpadding='0' cellspacing='1'>";
                echo "<tr>";
                echo "<td width='30' align='center' class='TableHeader' >STT</td>";
                echo "<td width='400' align='center' class='TableHeader' >Mã Đơn vị </td>";
                echo "<td width='900' align='center' class='TableHeader' >Tên Đơn vị </td>";
                echo "<td width='800' align='center' class='TableHeader'>Địa chỉ đơn vị </td>";
                echo "<td width='600' align='center' class='TableHeader'>Thông tin liên hệ </td>";
                echo "<td width='600' align='center' class='TableHeader'>Tên tài khoản </td>";
                echo "<td width='600' align='center' class='TableHeader'>Mật khẩu </td>";
                echo "<td width='50' align='center' class='TableHeader'>Quyền </td>";
                echo "<td width='50' align='center' class='TableHeader'>Chọn</td>";
                echo "</tr>";


                $num = mysql_num_rows($result);
                $i = 0;
                echo "<tbody style='display:none;'>";
                while ($row = mysql_fetch_array($result)) {
                    $i++;
                    if ($i % 2 == 0) {
                        echo "</tbody>";
                        echo "<tr>";
                        echo "<td align='center' class='TableField2'>" . $i . "</td>";
                        echo "<td  align='center' class='TableField2'><div id='madv$i'>" . $row['MA_DON_VI'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='tendv$i'>" . $row['TEN_DON_VI'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='diachidv$i'>" . $row['DIA_CHI_DV'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='lienhedv$i'>" . $row['LIEN_HE_DV'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='tentk$i'>" . $row['TEN_TK'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='matkhau$i'>" . $row['MAT_KHAU'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='quyen$i'>" . $row['QUYEN'] . "</div></td>";
                        echo "<td  align='center' class='TableField2'><input type='radio' name='chkchon' value='$i' onClick='getValue(this.value);' ></td>";
                        echo "</tr>";
                    } else {
                        echo "</tbody>";
                        echo "<tr>";
                        echo "<td align='center' class='TableField'>" . $i . "</td>";
                        echo "<td  align='center' class='TableField'><div id='madv$i'>" . $row['MA_DON_VI'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='tendv$i'>" . $row['TEN_DON_VI'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='diachidv$i'>" . $row['DIA_CHI_DV'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='lienhedv$i'>" . $row['LIEN_HE_DV'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='tentk$i'>" . $row['TEN_TK'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='matkhau$i'>" . $row['MAT_KHAU'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='quyen$i'>" . $row['QUYEN'] . "</div></td>";
                        echo "<td  align='center'  class='TableField'><input type='radio' name='chkchon' value='$i' onClick='getValue(this.value);' ></td>";
                        echo "</tr>";
                    }
                }
                echo "</tbody>";

                echo "<tr>";
                echo "<td align='left' colspan='9'><span style=' color:#008000'>Tổng số đơn vị: $num";
                echo "</span></td>";
                echo "<td align='right' colspan='2'><font color='green'>";
                echo "</font></td>";
                echo "</tr>";
                echo "</table></td>";
                echo "</tr>";
                echo "</table>";
                //}
                ?>
            </form>
            <!-- het bang -->
    </div>
</body>
</html>
